/*
 * Libwrapper.cpp
 *
 *  Created on: 2013-6-11
 *      Author: wb
 */

#include "Libwrapper.h"
#include <dlib/misc_api.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <dlib/compress_stream.h>
#include <dlib/base64.h>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/serialize.h>
#include <dlib/image_transforms.h>
#include <iostream>
#include <iomanip>
#include <dlib/dir_nav.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>

using namespace dlib;
using namespace std;

namespace s2e {
namespace plugins {

Libwrapper::Libwrapper() {

}

Libwrapper::~Libwrapper() {
}

void Libwrapper::init() {
}
bool Libwrapper::file_exists(const std::string& filename) {
	return dlib::file_exists(filename);
}

std::vector<file_dlib> Libwrapper::getfiles(std::string dirloc) {
	directory dirnav(dirloc);
	std::vector<file> files;
	std::vector<file_dlib> files_dlib;
	dirnav.get_files(files);
	sort(files.begin(), files.end());
	 for (unsigned long i = 0; i < files.size(); ++i)
	 {
		 file_dlib fdlib;
		 fdlib.file_size = files[i].size();
		 fdlib.name = files[i].name();
		 fdlib.full_name = files[i].full_name();
		 files_dlib.push_back(fdlib);
	 }
    return files_dlib;
}
void Libwrapper::sleep(unsigned long milliseconds) {
	dlib::sleep(milliseconds);
}
void Libwrapper::serialize(const transferstate& item, std::ostream& out) {
	 //std::deque<bool> m_forkrecord;
	 //std::deque<bool> m_forkrecord4repaly;
   //是否正在重播，当m_forkrecord4repaly变为空时，请将其设为false
     //bool m_replaying;
	/**/
	dlib::serialize(item.m_forkrecord, out);
	dlib::serialize(item.m_forkrecord4repaly, out);
	dlib::serialize(item.m_forkPoints, out);
	dlib::serialize(item.m_concreteAddressSequence, out);
		dlib::serialize(item.m_concreteAddressSequence4repaly, out);
	//dlib::serialize(item.m_isSpeculative, out);
	//dlib::serialize(item, out);
}

void Libwrapper::deserialize(transferstate& item, std::istream& in) {
	/**/
	dlib::deserialize(item.m_forkrecord, in);
	dlib::deserialize(item.m_forkrecord4repaly, in);
	dlib::deserialize(item.m_forkPoints, in);
	dlib::deserialize(item.m_concreteAddressSequence, in);
	dlib::deserialize(item.m_concreteAddressSequence4repaly, in);
	//dlib::deserialize(item.m_isSpeculative, in);
	//dlib::deserialize(item, in);
}

}
} /* namespace s2e */
